<template>
	<view>
		<view class="bb p2 " v-for="(item,index) in  list" :key="index">
			<view class="flex a-c j-b">
				<view class="ml2" style="width: 80%;">
					<view class="ml1 flex a-c">
						<text class="w800 f30">{{item.name}}</text>
						<text class="ml1 f30">{{item.tel}}</text>
						<view v-if="item.select==2" class="flex a-c j-c b_y ml1"
							style="width: 80rpx;height: 40rpx;border: solid #FFB400 2rpx;color: #FFB400;">
							默认
						</view>
					</view>
					<view class="pt1 ml1">
						<text class=" f28 ">{{item.addr}}-{{item.addr_details}}</text>
					</view>
				</view>
				<view class="" @click="on_add(item.id)">
					<text class="bicon f60   mr3">&#xe61c;</text>
				</view>
			</view>
			<view class="flex j-f pr2 pl2">
				<view v-if="id==1" @click="on_xz(item.id,index)" class="banmi_button_1 button_bg">
					<text class="f30">选择</text>
				</view>
				<view @click="on_del(item.id,index)" class="banmi_button_1 ml2" style="background-color: #D3D3D3;">
					<text class="f30" style="color: #000;">删除</text>
				</view>
			</view>
		</view>
		<view v-if="list.length==0" class="flex j-c a-c" style="height: 80vh;">
			<text class="f30 c_7">您还未设置收货地址</text>
		</view>
		<view @click="on_add(0)" class="q_y  t_c  cff  button_bg"
			style="position: fixed;width: 110rpx;height: 110rpx;right: 30px;bottom: 280rpx;z-index: 8">
			<view class="f28" style="padding-top: 20rpx;">
				添加
			</view>
			<view class="f28">
				地址
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				id: 0
			}
		},
		onLoad(on) {

			this.id = on.id;
			var that = this;
			uni.$on('banmi_addr', function(data) {
				that.token = uni.getStorageSync('token');
				that.init();
			})
			this.init();
		},
		methods: {
			on_xz(id, index) {
				uni.showToast({
					title: '选择成功,正在返回',
					icon: 'none'
				})
				var addr_find = this.list[index];
				setTimeout(function() {
					uni.$emit('banmi_buy_addr', {
						title: addr_find,
					});
					uni.navigateBack()
				}, 500);

			},
			on_del(id, index) {
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确认删除?',
					success: function(res) {
						if (res.confirm) {
							that.on_del_ajax(id, index);
						}
					}
				});
			},
			on_del_ajax(id, index) {
				var that = this;
				let requestParams = {
					id: id
				};
				this.Http.post('/banmi.php/User/UserAddrDel', requestParams).then(ret => {
					uni.showToast({
						title: ret.msg,
						icon: 'none'
					})
					if (ret.status == 200) {
						that.list = that.list.filter(t => t.id != id);
						return
					}

				})
			},
			on_add(id) {
				uni.navigateTo({
					url: '/pages/banmi/add_addr?id=' + id
				})
			},
			init() {
				var that = this;
				let requestParams = {};
				this.Http.post('/banmi.php/User/UserAddr',requestParams).then(ret => {
					if (ret.status == 200) {
						this.list = ret.data.list
						return
					}
				})
			}

		}
	}
</script>

<style>


</style>